package org.example.salesystem.service.impl;

import org.example.salesystem.entity.ResultBody;
import org.example.salesystem.mapper.SearchMapper;
import org.example.salesystem.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SearchServiceimpl implements SearchService {
    @Autowired
    private SearchMapper searchMapper;
//    @Override
//    public List<Map<String,Object>> searchByName(String name) {
//        List<Map<String,Object>> list=searchMapper.searchByName(name);
//        if(!list.isEmpty())
//        {
//            return list;
//        }
//        return null;
//    }
//    @Override
//    public List<Map<String,Object>> searchByKind(String kind) {
//        List<Map<String,Object>> list=searchMapper.searchByKind(kind);
//        if(!list.isEmpty())
//        {
//            return list;
//        }
//        return null;
//    }
//
//    @Override
//    public ResultBody searchGoodsByPrice(double minprice, double maxprice) {
//        List<Map<String,Object>> list=searchMapper.searchGoodsByPrice(minprice,maxprice);
//        if(!list.isEmpty())
//        {
//            return new ResultBody(200,"查询成功",list,list.size());
//        }
//        return new ResultBody(400,"暂无商品",false);
//    }
@Override
public ResultBody searchByName(Map<String,Object>map) {
    if(!searchMapper.searchByName(map).isEmpty())
    {
        return new ResultBody(200,"查询成功",searchMapper.searchByName(map),searchMapper.searchByName(map).size());
    }
    else if(searchMapper.searchByName(map).isEmpty())
    {
        return new ResultBody(200,"暂无商品",searchMapper.searchByName(map));
    }
    return new ResultBody(500,"查询失败",false);
}
    //    按照类别进行查询
    @Override
    public ResultBody searchByKind(Map<String,Object>map) {
        if(!searchMapper.searchByKind(map).isEmpty())
        {
            return new ResultBody(200,"查询成功",searchMapper.searchByKind(map),searchMapper.searchByKind(map).size());
        }
        else if(searchMapper.searchByKind(map).isEmpty())
        {
            return new ResultBody(200,"暂无商品",searchMapper.searchByKind(map));
        }

        return new ResultBody(500,"查询失败",false);
    }

    //当传空值时，查询所有商品
    @Override public ResultBody search() {
        List<Map<String,Object>> list=searchMapper.search();
        if(!list.isEmpty())
        {
            return new ResultBody(200,"查询成功",list,list.size());
        }
        return new ResultBody(400,"暂无商品",false);
    }
}
